﻿using System;
using System.IO.Compression;

namespace FtpUploadWeb.Common
{
    /// <summary>
    /// 压缩文件帮助类
    /// </summary>
    public class ZipFileHelper
    {
        private static string zipPath;
        /// <summary>
        /// 压缩文件夹
        /// </summary>
        public static void UpZip()
        {
            string startPath = FtpHelper.upLoadFileDirectory;//@"d:\FTP测试";
            zipPath = FtpHelper.upLoadFileDirectory + DateTime.Now.ToString("yyyyMMddHHmm") + ".zip";
            //添加文件到指定压缩文件中
            try
            {
                ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);
                TaskManage.WriteTextLog("UpZip", "压缩完成:" + zipPath);
            }
            catch (Exception ex)
            {
                TaskManage.WriteTextLog("UpZip", "压缩错误:" + ex.ToString());
            }
        }

        public static string getZipFilePath()
        {
            return zipPath;
        }
    }
}
